home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / db / esm-3.1 / esm-3 / usr / local / sm / src / serverlib / undo / undoFileKeyInsert.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-05  |  7.5 KB  |  292 lines

  1. /*
  2.  *   $RCSfile: undoFileKeyInsert.c,v $  
  3.  *   $Revision: 1.1.1.1 $  
  4.  *   $Date: 1996/05/04 21:56:03 $      
  5.  */ 
  6. /**********************************************************************
  7. * EXODUS Database Toolkit Software
  8. * Copyright (c) 1991 Computer Sciences Department, University of
  9. *                    Wisconsin -- Madison
  10. * All Rights Reserved.
  11. *
  12. * Permission to use, copy, modify and distribute this software and its
  13. * documentation is hereby granted, provided that both the copyright
  14. * notice and this permission notice appear in all copies of the
  15. * software, derivative works or modified versions, and any portions
  16. * thereof, and that both notices appear in supporting documentation.
  17. *
  18. * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
  19. * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.  
  20. * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
  21. * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  22. *
  23. * The EXODUS Project Group requests users of this software to return 
  24. * any improvements or extensions that they make to:
  25. *
  26. *   EXODUS Project Group 
  27. *     c/o David J. DeWitt and Michael J. Carey
  28. *   Computer Sciences Department
  29. *   University of Wisconsin -- Madison
  30. *   Madison, WI 53706
  31. *
  32. *     or exodus@cs.wisc.edu
  33. *
  34. * In addition, the EXODUS Project Group requests that users grant the 
  35. * Computer Sciences Department rights to redistribute these changes.
  36. **********************************************************************/
  37.  
  38. #include "sysdefs.h"
  39. #include "ess.h"
  40. #include "checking.h"
  41. #include "trace.h"
  42. #include "error.h"
  43. #include "list.h"
  44. #include "pool.h"
  45. #include "tid.h"
  46. #include "io.h"
  47. #include "lock.h"
  48. #include "object.h"
  49. #include "msgdefs.h"
  50. #include "thread.h"
  51. #include "latch.h"
  52. #include "semaphore.h"
  53. #include "link.h"
  54. #include "lsn.h"
  55. #include "bf.h"
  56. #include "log.h"
  57. #include "volume.h"
  58. #include "logrecs.h"
  59. #include "openlog.h"
  60. #include "trans.h"
  61. #include "bitmap.h"
  62. #include "file.h"
  63. #include "consist.h"
  64. #include "undo.h"
  65. #include "io_extfuncs.h"
  66. #include "bf_extfuncs.h"
  67. #include "bm_extfuncs.h"
  68. #include "fi_extfuncs.h"
  69. #include "fi_macro.h"
  70. #include "fi_intfuncs.h"
  71. #include "log_extfuncs.h"
  72. #include "undo_extfuncs.h"
  73. #include "logaction.h"
  74. #include "util_funcs.h"
  75. #include "thread_globals.h"
  76. #include "bf_globals.h"
  77.  
  78.  
  79.  void
  80. undoFileKeyInsert (
  81.  
  82.     LOGRECORDHDR        *recordHeader 
  83. )
  84. {
  85.  
  86.     register VOLREC        *volRec;
  87.     register PID        *pid;
  88.     register FOUR        *insertLoc;
  89.     register SHORTPID    *key;
  90.     register NODEPAGE    *nodePage;
  91.     register GROUPLINK    *nodeLink;
  92.     LOGRECORDINFO        recordInfo;
  93.     FORCEMARK            forceMark;
  94.     LSN                    lsn;
  95.     LRC                    *lrc;
  96.  
  97.     TRPRINT(TR_IO, TR_LEVEL_1, ("lsn:%d", recordHeader->recordLSN.offset));
  98.  
  99.     /*
  100.      *    get a pointer to the page in the record
  101.      */
  102.     pid = (PID *) &(recordHeader->actionPid);
  103.     TRPRINT(TR_IO, TR_LEVEL_2, ("pid:%d", pid->page));
  104.  
  105.     /*
  106.      *    get a pointer to the name in the record
  107.      */
  108.     insertLoc = (FOUR *) GET_LOG_IMAGE(recordHeader, 0);
  109.     TRPRINT(TR_IO, TR_LEVEL_2, ("insertLoc:%d", *insertLoc));
  110.  
  111.     /*
  112.      *    get a pointer to the name in the record
  113.      */
  114.     key = (SHORTPID *) GET_LOG_IMAGE(recordHeader, 1);
  115.     TRPRINT(TR_IO, TR_LEVEL_2, ("key:%d", *key));
  116.  
  117.     /*
  118.      *    check to see if the volume is mounted
  119.      */
  120.     if ((volRec = io_FindVolRec(pid->volid)) == NULL)    {
  121.  
  122.         SM_ERROR(TYPE_FATAL, Active->errno);
  123.     }
  124.  
  125.     /*
  126.      * Read in first page of file and grab node type
  127.      */
  128.     if ((nodeLink = bf_ReadPage(UserBufGroup, pid, FILE_PAGE2SIZE, BF_SEM)) == NULL) {
  129.  
  130.         SM_ERROR(TYPE_FATAL, Active->errno);
  131.     }
  132.  
  133.     /*
  134.      *    get a pointer to the node page
  135.      */
  136.     nodePage = (NODEPAGE *) nodeLink->bufFrame;
  137.  
  138.     /*
  139.      *    remove the key
  140.      */
  141.     FI_DeleteFromArray(nodePage, *insertLoc, *key);
  142.     fi_PrintNode(nodePage);
  143.  
  144.     /*
  145.      *  increment the lrc on the page
  146.      */
  147.     lrc = &(((NODEHEADER *) nodeLink->bufFrame)->lrc);
  148.     INCREMENT_LRC(lrc);
  149.  
  150.     /*
  151.      *    initialize the log information
  152.      */
  153.     recordInfo.type            = LOG_REC_TYPE_COMPENSATION;
  154.     recordInfo.action        = LOG_ACTION_DELETE_FILE_KEY;
  155.     recordInfo.imageCount    = 2;
  156.     recordInfo.actionPid    = pid;
  157.     recordInfo.actionLRC    = lrc;
  158.     recordInfo.imageSize[0] = sizeof(FOUR);
  159.     recordInfo.imageData[0] = (VOID *) insertLoc;
  160.     recordInfo.imageSize[1] = sizeof(SHORTPID);
  161.     recordInfo.imageData[1] = (VOID *) key;
  162.     recordInfo.flags        = NOFLAGS;
  163.     recordInfo.nextUndoLSN    = recordHeader->previousLSN;
  164.  
  165.     /*
  166.      *    write the record to the log
  167.      */
  168.     if ((forceMark = writeLogRecord((TRANSREC *) Active->transRec, &recordInfo,
  169.                               &lsn, NOFLAGS)) < 0)    {
  170.         
  171.         SM_ERROR(TYPE_FATAL, Active->errno);
  172.     }
  173.  
  174.     /*
  175.      *    mark the page dependency
  176.      */
  177.     DEPEND_LOG(nodeLink->pageHash, forceMark, &lsn, lrc);
  178.  
  179.     /*
  180.      *    release  the page semaphore
  181.      */
  182.     signalSemaphore( &(nodeLink->pageHash->semaphore) );
  183.  
  184.     /*
  185.      *    release and dirty the page
  186.      */
  187.     bf_UnfixPage(nodeLink, BF_DEFAULT, TRUE);
  188. }
  189.  
  190.  
  191.  
  192.  void
  193. undoFileKeyDelete (
  194.  
  195.     LOGRECORDHDR        *recordHeader 
  196. )
  197. {
  198.  
  199.     VOLREC            *volRec;
  200.     SHORTPID        *key;
  201.     FILEKEYLOGINFO    *fileKeyLogInfo;
  202.     SHORTPID        dummy;
  203.  
  204.     TRPRINT(TR_IO, TR_LEVEL_1, ("lsn:%d", recordHeader->recordLSN.offset));
  205.  
  206.     /* get a pointer to the key to insert */
  207.     key = (SHORTPID *) GET_LOG_IMAGE(recordHeader, 1);
  208.     TRPRINT(TR_IO, TR_LEVEL_2, ("key:%d", *key));
  209.  
  210.     /* get a pointer to the fid and lg obj info */
  211.     fileKeyLogInfo = (FILEKEYLOGINFO *) GET_LOG_IMAGE(recordHeader, 2);
  212.     TRPRINT(TR_IO, TR_LEVEL_2, ("fid:%d:%d", fileKeyLogInfo->fid.pid.page, (int) (fileKeyLogInfo->fid.pid.volid) ));
  213.  
  214.     /* check to see if the volume is mounted */
  215.     if ((volRec = io_FindVolRec(fileKeyLogInfo->fid.pid.volid)) == NULL)    {
  216.  
  217.         SM_ERROR(TYPE_FATAL, Active->errno);
  218.     }
  219.     /*
  220.      *    Logically insert a new page into the file
  221.      */
  222.     
  223.     /*  insert the page in the file */
  224.     if (fi_InsertPage(UserBufGroup, &(fileKeyLogInfo->fid),
  225.                         *key, fileKeyLogInfo->largeObjOnPage, &dummy)) {
  226.         SM_ERROR(TYPE_FATAL, Active->errno);
  227.     }
  228.  
  229.     /* log a compensation for the insert */
  230.     if (FI_LogKeyInsertDone(&(fileKeyLogInfo->fid), *key, recordHeader->previousLSN)) {
  231.         SM_ERROR(TYPE_FATAL, Active->errno);
  232.     }
  233. }
  234.  
  235.  void
  236. undoFileKeyInsertDone(
  237.  
  238.     LOGRECORDHDR        *recordHeader 
  239. )
  240. {
  241.     FID            *fid;
  242.     SHORTPID     *key;
  243.     PID            pid;
  244.     VOLREC        *volRec;
  245.     TRANSREC    *transRec = (TRANSREC*) Active->transRec;
  246.  
  247.     CHECK_TRANSREC_MAGIC(transRec);
  248.  
  249.     /* get a pointer to the fid and lg obj info */
  250.     fid = (FID *) GET_LOG_IMAGE(recordHeader, 0);
  251.     TRPRINT(TR_IO, TR_LEVEL_2, ("fid:%d:%d", fid->pid.page, (int) (fid->pid.volid) ));
  252.  
  253.     /* get a pointer to the key to insert */
  254.     key = (SHORTPID *) GET_LOG_IMAGE(recordHeader, 1);
  255.     TRPRINT(TR_IO, TR_LEVEL_2, ("key:%d", *key));
  256.  
  257.     /*
  258.      *    The following steps are a little delicate.  The first thing
  259.      *    is to deallocate the page and log the deallocation.  This
  260.      *    is a normal log record.  Then we mark the page as no longer
  261.      *    slotted.  This is also logged.  Finally, we remove the page from
  262.      *    the file.  This is logged as a compensation record wrapping
  263.      *    around the the previous records.
  264.      */
  265.  
  266.     /* log removing the page from the bitmap */
  267.     pid.page = *key;
  268.     pid.volid = fid->pid.volid;
  269. #ifdef JUNK
  270.     if (io_DeallocPages(SLOTTED_PAGE2SIZE, 1, &pid, NULL, TRUE, TRUE) != esmNOERROR) {
  271. #endif
  272.     if (io_FakeDeallocPages(SLOTTED_PAGE2SIZE, 1, &pid, &(transRec->pageDeallocList), PAGE_SLOTTED) != esmNOERROR) {
  273.         SM_ERROR(TYPE_FATAL, Active->errno);
  274.     }
  275.     bf_InvalidatePage(&pid);    
  276.  
  277.  
  278.     /* mark the page as no longer slotted */
  279.     if ((volRec = io_FindVolRec(pid.volid)) == NULL)   {
  280.         SM_ERROR(TYPE_FATAL, Active->errno);
  281.     }
  282.     if (io_MarkPage(volRec, &pid, PAGE_SLOTTED, FALSE) != esmNOERROR) {
  283.         SM_ERROR(TYPE_FATAL, Active->errno);
  284.     }
  285.  
  286.     if (fi_DeletePage(UserBufGroup, fid, *key, recordHeader->previousLSN) != esmNOERROR) {
  287.         SM_ERROR(TYPE_FATAL, Active->errno);
  288.     }
  289.  
  290.     return;
  291. }
  292.